<template>
	<view class="pages">
		<!-- 顶部空余 -->
		<view style="width: 100%;height: var(--status-bar-height)"></view>
		<view class="nav_top">
			<uni-icons type="back" @click="back" size="26"></uni-icons>
			<view class="text">{{$t('index.allType.All')}}</view>
			<uni-icons type="search" @click="go('/pages/shop/index/search')" size="22"></uni-icons>
		</view>
		<view class="content">
			<view class="left">
				<scroll-view class="scroll_view" scroll-y="true">
					<view @click="changeItem(item.id)" :class="active==item.id?'active_scroll_item scroll_item':'scroll_item'" v-for="item in list1">
						<view style="text-align: center;">{{item.name}}</view>
					</view>
				</scroll-view>
			</view>
			<view class="right">
				<scroll-view class="right_scroll" scroll-y="true">
					<view class="right_item" v-for="item in list2" @click="goSearch1(item)" >
						<view class="item_title">{{item.name}}</view>
						<view class="item_list">
							<view class="list_item" @click="goSearch(items)" v-for="items in item.chlid">
								<div class="img">
									<image :src="items.image||items.mainimg"></image>
								</div>
								<view class="text">{{items.name}}</view>
							</view>
						</view>
					</view>
				</scroll-view>
			</view>
		</view>
	</view>
</template>

<script>
	import { shopCate, cateList, getSetting } from '@/api/api.js'
	export default {
		data() {
			return {
				active: 1,
				// 左侧分类
				list1: [],
				// 右侧分类
				list2: [],
				qianggou_cate_id: null
			}
		},
		onLoad(type) {
			if (type.type) {
				this.active = type.type
			}
			getSetting().then(res =>{
				this.qianggou_cate_id  = res.data.data.qianggou_cate_id
				this.getNav()
			})
			this.getNav()
		},
		methods: {
			// 获取一级分类
			getNav() {
				shopCate({
					first_id: 0
				}).then(res => {
					this.list1 = res.data.data
					this.getNavList()
				})
			},
			// 获取二级分类
			getNavList() {
				cateList({
					first_id: this.active
				}).then(res => {
					this.list2 = res.data.data
					for (var j = 0; j < this.list1.length; j++) {
						if (this.qianggou_cate_id == this.list1[j].id) {
							this.qiang = this.list1[j]
							this.list1.splice(j, 1);
						}
					}
				})
			},
			go(url) {
				uni.navigateTo({
					url: url
				})
			},
      goSearch1(item) {
        if(item.chlid!=undefined && item.chlid.length>0){
          return
        }
      		uni.navigateTo({
      			url: `/pages/shop/index/search?id=${item.id}&source=cate`
      		})
      },
			goSearch(item) {
				if(!item.detail){
					uni.navigateTo({
						url: `/pages/shop/index/search?idArr=${JSON.stringify(item)}`
					})
				}else{
					uni.navigateTo({
						url: `/pages/shop/goodDetail/goodDetail?id=${item.id}`
					})
				}
			},
			changeItem(id) {
				this.active = id
				this.goodLists = []
				this.getNavList()
			},
			back() {
				uni.navigateBack()
			}
		}
	}
</script>

<style lang="scss" scoped>
	.pages {
		width: 100%;
		min-height: 100vh;
		background-color: #f6f5fa;
	}

	.nav_top {
		position: fixed;
		top: 0;
		left: 0;
		right: 0;
		width: 100%;
		padding: 0 20rpx;
		height: 100rpx;
		background-color: #fff;
		display: flex;
		justify-content: space-between;
		align-items: center;

		.text {
			font-weight: bold;
		}
	}

	.content {
		padding-top: 100rpx;
		display: flex;
		justify-content: space-between;

		.left {
			width: 30%;
			display: flex;
			justify-content: center;

			.scroll_view {
				height: calc(100vh - 100rpx);

				.scroll_item {
					padding: 20rpx 20rpx;
					// height: 100rpx;
					display: flex;
					font-size: 32rpx;
					justify-content: center;
					align-items: center;
				}

				.active_scroll_item {
					font-size: 38rpx;
					font-weight: bold;

					view {
						padding: 10rpx 0;
						border-bottom: 6rpx solid #1cc8c9;
					}
				}
			}
		}

		.right {
			width: 75%;
			height: calc(100vh - 120rpx);

			// overflow: auto;
			.right_scroll {
				height: calc(100vh - 100rpx);

			}

			.right_item {
				background-color: #fff;
				width: 100%;
				margin-top: 20rpx;

				.item_title {
					padding: 30rpx 30rpx;
					padding-bottom: 0rpx;
					font-weight: bold;
				}

				.item_list {
					width: 100%;
					display: flex;
					flex-wrap: wrap;

					.list_item {
						width: 33.3%;
						height: 200rpx;
						margin: 35rpx 0;
						display: flex;
						flex-direction: column;
						justify-content: center;

						.img {
							width: 100%;
							height: 150rpx;
							display: flex;
							align-items: flex-end;
							justify-content: center;

							image {
								width: 150rpx;
								height: 150rpx;
							}
						}

						.text {
							width: 100%;
							margin-top: 5rpx;
							text-align: center;
							font-size: 28rpx;

						}
					}
				}
			}
		}

	}
</style>